"""
文件名: CartInterface
 - 1.录入购物车模块接口
"""
from interface.member import MemberInterface
from utils.send_method import SendMethod


class CartInterface:
    def __init__(self, headers):
        self.url = 'http://47.108.206.100:8085'
        self.headers = headers

    def cart_add(self, body):
        """
        添加购物车接口
        :param body: 添加购物车请求参数
        :return:
        """
        method = 'post'  # 请求参数类型json
        url = self.url + '/cart/add'
        return SendMethod.send_method(method=method, url=url, json=body, headers=self.headers)


if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    body = {
        "username": "jack",
        "password": "123456"
    }
    headers = MemberInterface().get_token(body)
    print(headers)
    cart = CartInterface(headers)
    payload = {
        "createDate": "2022-06-10T02:01:35.734Z",
        "deleteStatus": 0,
        "id": 0,
        "memberId": 13,
        "memberNickname": "tom",
        "modifyDate": "2022-06-10T04:01:35.734Z",
        "price": 2699,
        "productAttr": '[{"key":"颜色","value":"黑色"},{"key":"容量","value":"32G"}]',
        "productBrand": "小米",
        "productCategoryId": 19,
        "productId": 27,
        "productName": "小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180615/xiaomi.jpg",
        "productSkuCode": "201808270027001",
        "productSkuId": 98,
        "productSn": "7437788",
        "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄，AI语音助手小米6X低至1299，点击抢购",
        "quantity": 1
    }
    print(cart.cart_add(payload))  # 调用添加购物车
    # print(cart.get_cart_list())  # 调用查看购物车
